package reflectx

import (
	"gitee.com/zhongguo168a/gocodes/datax/schemax"
)

type MapTypeRef struct {
}

func (f *MapTypeRef) RefHas(field string) bool {
	switch field {
	case "Key":
		return true
	case "Value":
		return true
	}
	return false
}
func (f *MapTypeRef) RefGet(target IRefObject, MapType string) (val interface{}, isNil bool) {
	obj := target.(*schemax.MapType)
	switch MapType {
	case "Key":
		return obj.Key, obj.Key == nil
	case "Value":
		return obj.Value, obj.Value == nil
	}
	return nil, true
}

func (f *MapTypeRef) RefSet(target IRefObject, MapType string, val interface{}) {
	obj := target.(*schemax.MapType)
	switch MapType {
	case "Key":
		obj.Key = val.(schemax.IType)
	case "Value":
		obj.Value = val.(schemax.IType)
	}
	return
}

func (f *MapTypeRef) RefNew() IRefObject {
	return &schemax.MapType{}
}

func (f *MapTypeRef) RefType() string {
	return "map"
}
